﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading;
using System.Configuration;
//using SWFToImage;

namespace MonitorFileConvert
{
    public partial class Main : Form
    {
        //  WsVideoResource.FileConvert ws = new MonitorFileConvert.WsVideoResource.FileConvert();
        public Thread nonParameterThread;
        public Main()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }
        private string strCutTimeStr = System.Configuration.ConfigurationSettings.AppSettings["CutTime"].ToString();
        private int iMin = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["Min"].ToString());

        private void btnBegin_Click(object sender, EventArgs e)
        {

            nonParameterThread = new Thread(new ThreadStart(ConvertStart));
            nonParameterThread.Start();
        }

        private void ConvertStart()
        {
            //链接数据库
            btnBegin.Visible = false;
            int iRowCount = 0;

            //using (DataSet ds = ws.GetResourceTask())
            //{
            //    if (ds != null)
            //    {
            //        iRowCount = ds.Tables[0].Rows.Count;
            //        if (iRowCount > 0)
            //        {
            //            DataRow dr = ds.Tables[0].Rows[0];
            //            //转换格式
            //            ConvertFile(int.Parse(dr["FileID"].ToString()), dr["FileURL"].ToString());
            //        }
            //        else
            //        {
            //            txtStatus.Text += "等待转换文件……！\r\n";
            //            Thread.Sleep(iMin * 60 * 1000);
            //        }
            //        ConvertStart();
            //    }
            //}

            ConvertFile(0, @"/resource/video.mp4");



        }
        /// <summary>
        /// 获取pdf页数
        /// </summary>
        /// <param name="pdfPath"></param>
        /// <returns></returns>
        public static int GetPageCount(string pdfPath)
        {
            try
            {
                byte[] buffer = File.ReadAllBytes(pdfPath);

                int length = buffer.Length;

                if (buffer == null)

                    return -1;

                if (buffer.Length <= 0)

                    return -1;

                string pdfText = Encoding.Default.GetString(buffer);

                System.Text.RegularExpressions.Regex rx1 = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]");

                System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText);

                return matches.Count;

            }
            catch (Exception ex)
            {
                return 0;
                //throw ex;   
            }

        }

        /// <summary>
        /// 转换操作
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="iFileID">任务ID</param>
        /// <param name="ResourceID">资源ID</param>
        /// <param name="strVideoPath">视频存放路径</param>
        /// <param name="strFileName">视频名称</param>
        /// <param name="strSavePath">保存路径</param>
        /// <param name="strBigImage">大图大小</param>
        /// <param name="strSmallImage">小图大小</param>
        /// <param name="strCutTimeStr">预览视频截取时间</param>
        /// <param name="strImagePath">图片存放地址</param>
        private void ConvertFile(int iFileID, string strVideoPath)
        {
            try
            {
                string strTempSavePath = System.Configuration.ConfigurationSettings.AppSettings["SavePath"].ToString();
                string strOldPath = System.Configuration.ConfigurationSettings.AppSettings["OldPath"].ToString();

                string strFileType = strVideoPath.Substring(strVideoPath.LastIndexOf("."));
                string strDocFormat = System.Configuration.ConfigurationSettings.AppSettings["DocFormat"].ToString();
                string strMp3Format = System.Configuration.ConfigurationSettings.AppSettings["Mp3"].ToString();

                string strBigImage = string.Empty;
                string strSmallImage = string.Empty;
                //源文件路径
                strOldPath = strOldPath + strVideoPath.Replace("/", "\\");
                //保存相对路径
                string strTmepPath = strVideoPath.Substring(0, strVideoPath.LastIndexOf(@"/"));
                if (File.Exists(strOldPath))//源文件存在
                {
                    if (!Directory.Exists(strTempSavePath + strTmepPath))//保存文件的路径不存在 就创建
                    {
                        Directory.CreateDirectory(strTmepPath + strTmepPath);
                    }
                    //ws.BeginConvert(iFileID);
                    txtStatus.Text += "开始转换文件\"" + strOldPath + "\"！\r\n";
                    #region 视频 MP3
                    if (strDocFormat.IndexOf(strFileType) < 0)
                    {
                        string strFfmpegPath = Application.StartupPath + (@"\ffmpeg.exe");
                        #region wma...
                        if (strMp3Format.IndexOf(strFileType) >= 0)
                        {
                            strTempSavePath = strTempSavePath + strTmepPath + strVideoPath.Replace("/", "\\").Replace(strFileType, ".mp3");
                            //string strTmepPath=strTempSavePath.Substring(0,strTempSavePath.LastIndexOf(@"\"));

                            if (File.Exists(strTempSavePath))//转换后的文件已存在就删除
                            {
                                File.Delete(strTempSavePath);
                            }
                            StringBuilder sb = new StringBuilder();
                            sb.Append(" -i \"" + strOldPath + "\"");//output    

                            //sb.Append(" \"" + strTempSavePath + "\" ");//input 
                            Process p = new Process();
                            p.StartInfo.FileName = strFfmpegPath;
                            p.StartInfo.Arguments = sb.ToString();
                            p.StartInfo.UseShellExecute = false;
                            p.StartInfo.RedirectStandardError = true;
                            p.StartInfo.CreateNoWindow = false;

                            p.Start();//启动线程 

                            string str = p.StandardError.ReadToEnd();//开始同步读取 
                            p.Close();//关闭进程 
                            p.Dispose();//释放资源 
                            //获取时长
                            Regex reg = new Regex("duration:\\s*(.*?),", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            int iTimeLength = 0;
                            if (reg.IsMatch(str))
                            {
                                Match match = reg.Match(str);
                                iTimeLength = GetSecondsByString(match.Groups[1].Value);
                            }

                            sb.Append(" \"" + strTempSavePath + "\" ");//input 
                            Process pro = new Process();
                            pro.StartInfo.FileName = strFfmpegPath;
                            pro.StartInfo.Arguments = sb.ToString();
                            pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            pro.Start();

                            if (File.Exists(strTempSavePath))
                            {
                                txtStatus.Text += "转换完毕！\r\n";
                                //ws.ConvertSuccess(iFileID, iTimeLength, strVideoPath.Replace(strFileType, ".mp3"), "", "");
                            }
                            else
                            {
                                txtStatus.Text += "文件\"" + strOldPath + "\"转换失败!请检查文件是否能正常使用!\r\n";
                                // ws.ConvertFail(iFileID);
                            }
                        }
                        #endregion
                        else
                        {
                            #region mp3
                            if (strFileType.ToLower() == ".mp3")
                            {
                                strTempSavePath = strTempSavePath + strVideoPath.Replace("/", "\\");
                                //int iTimeLength = 0;//读MP3 时长
                                if (!File.Exists(strTempSavePath))
                                {
                                    File.Copy(strOldPath, strTempSavePath);
                                }
                                //ws.ConvertSuccess(iFileID, 0, strVideoPath, "", "");
                            }
                            #endregion
                            else
                            {
                                #region swf
                                if (strFileType.ToLower() == ".swf")
                                {
                                    string strBigimage = strVideoPath.Replace(".swf", "_big.jpg");
                                    string strSmalimage = strVideoPath.Replace(".swf", "_small.jpg");
                                    SwfToImage(strOldPath, strBigimage, strSmalimage);

                                    //ws.ConvertSuccess(iFileID, 0, strVideoPath, strBigimage, strSmalimage);
                                }
                                #endregion

                                else
                                {
                                    #region //视频格式
                                    strTempSavePath = strTempSavePath + strVideoPath.Replace("/", "\\").Replace(strFileType, ".flv");
                                    string strImagePath = strTempSavePath.Substring(0, strTempSavePath.LastIndexOf("\\"));
                                    if (!Directory.Exists(strImagePath))
                                    {
                                        Directory.CreateDirectory(strImagePath);
                                    }

                                    if (File.Exists(strTempSavePath))
                                    {
                                        //File.Delete(strTempSavePath);
                                    }
                                    //ws.BeginConvert(iFileID);
                                    //txtStatus.Text += "开始转换文件\"" + strOldPath + "\"！\r\n";
                                    //获取时长 //视频宽度和高度
                                    Process p = new Process();//建立外部调用线程 
                                    p.StartInfo.FileName = strFfmpegPath; //要调用外部程序的绝对路径 
                                    p.StartInfo.Arguments = " -i \"" + strOldPath.Trim() + "\"";//参数(这里就是FFMPEG的参数了)
                                    p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN) 
                                    p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的) 
                                    p.StartInfo.CreateNoWindow = false;//不创建进程窗口 
                                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                                    p.Start();//启动线程 
                                    // p.WaitForExit();//等待完成 
                                    string str = p.StandardError.ReadToEnd();//开始同步读取 
                                    p.Close();//关闭进程 
                                    p.Dispose();//释放资源 
                                    //处理方法...
                                    Regex reg = new Regex("duration:\\s*(.*?),", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                                    int iTimeLength = 0;
                                    if (reg.IsMatch(str))
                                    {
                                        Match match = reg.Match(str);
                                        iTimeLength = GetSecondsByString(match.Groups[1].Value);
                                    }

                                    Regex reg1 = new Regex("\\s(\\d+)[x](\\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                                    string strSize = string.Empty;
                                    if (reg1.IsMatch(str))
                                    {
                                        Match match = reg1.Match(str);
                                        strSize = match.Groups[0].Value;
                                        string[] strArray = strSize.Split('x');
                                        if (strArray.Length == 2)
                                        {
                                            int iWidth = int.Parse(strArray[0]);
                                            int iHeight = int.Parse(strArray[1]);
                                            if (Convert.ToDecimal(iWidth * 1.0 / iHeight) == Convert.ToDecimal(16.0 / 9))
                                            {
                                                strBigImage = System.Configuration.ConfigurationSettings.AppSettings["BigImage2"].ToString();
                                                strSmallImage = System.Configuration.ConfigurationSettings.AppSettings["SmallImage2"].ToString();
                                            }
                                            else
                                            {
                                                strBigImage = System.Configuration.ConfigurationSettings.AppSettings["BigImage"].ToString();
                                                strSmallImage = System.Configuration.ConfigurationSettings.AppSettings["SmallImage"].ToString();
                                            }
                                        }
                                    }
                                    if (strFileType != ".flv")
                                    {
                                        string strChangExePath = Application.StartupPath + (@"\ffmpeg.exe");
                                        CreateProcessForFFMpeg(strChangExePath, " -y -i \"" + strOldPath + "\""
                                           + " -ab 128k "// 设置音频码率,一般是选择32、64、96或128这几种
                                + " -acodec libmp3lame"//+ " -acodec libmp3lame"//对音频的acodec则是指定编码方式，可以指定为libmp3lame或aac等，这两种分别是指使用mp3和aac格式的音频
                                           + " -ar 22050"//设置音频采样率,对于音频的ar（采样率）可以指定为22050、24000、44100或48000，一般来将后两种比较常见
                                           + " -qmin 2"//
                                           + " -qmax 16"//
                                           + " -b 200k"//设置比特率,缺省200kb/s
                                            //+ " -qscale 6"//使用动态码率来设置
                                           + " -r 25" //设置帧频,缺省25
                                           + " -s \"600*480\""//视频尺寸
                                            //+ " -s \"" + strBigImage +"\""//视频尺寸
                                           + " \"" + strTempSavePath + "\"", true);
                                        //CreateProcessForFFMpeg(strFfmpegPath, " -i \"" + strOldPath + "\""
                                        //               + " -ab 128 "// 设置音频码率,一般是选择32、64、96或128这几种
                                        //    //+ " -an -vcodec libx264 -fpre "//
                                        //               + " -acodec libmp3lame"//对音频的acodec则是指定编码方式，可以指定为libmp3lame或aac等，这两种分别是指使用mp3和aac格式的音频
                                        //               + " -ar 22050"//设置音频采样率,对于音频的ar（采样率）可以指定为22050、24000、44100或48000，一般来将后两种比较常见
                                        //               + " -qmin 2"//
                                        //               + " -qmax 16"//
                                        //               + " -b 200k"//设置比特率,缺省200kb/s
                                        //    //+ " -qscale 6"//使用动态码率来设置
                                        //               + " -r 25" //设置帧频,缺省25
                                        //               + " -s \"" + strBigImage + "\""//视频尺寸
                                        //               + " \"" + strTempSavePath + "\"", false);
                                        //txtStatus.Text += "文件\"" + strOldPath + "\"转换完毕！\r\n";
                                    }
                                    else
                                    {
                                        if (strFileType == ".flv" && !File.Exists(strTempSavePath))
                                        {

                                            System.IO.File.Copy(strOldPath, strTempSavePath);

                                        }
                                    }

                                    //检测是否转换成功  检测文件是否存在并且文件大小是否为0
                                    if (File.Exists(strTempSavePath) && new FileInfo(strTempSavePath).Length > 0)
                                    {
                                        #region
                                        //if (new FileInfo(strVideoPath).Name == strNewFileName)
                                        //{
                                        //    File.Copy(strVideoPath, strVideoPath.Substring(0, strVideoPath.LastIndexOf('.') - 1) + "_temp" + DateTime.Now.ToShortTimeString() + strVideoPath.Substring(strVideoPath.LastIndexOf('.')));
                                        //}
                                        //else
                                        //{
                                        //    if (File.Exists(strSavePath))
                                        //    {
                                        //        File.Delete(strSavePath);
                                        //    }
                                        //}
                                        //File.Move(strTempSavePath, strSavePath);

                                        //string[] strCutTime = strCutTimeStr.Split('|');
                                        //string strCutVideoPath = strSavePath.Replace(".flv", "_preview.flv");

                                        //if (File.Exists(strCutVideoPath))
                                        //{
                                        //    File.Delete(strCutVideoPath);
                                        //}

                                        //CreateProcessForFFMpeg(strFfmpegPath, " -y -i " + strVideoPath
                                        //+ " -ab 128 "// 设置音频码率,一般是选择32、64、96或128这几种
                                        //    //+ " -acodec libmp3lame"//对音频的acodec则是指定编码方式，可以指定为libmp3lame或aac等，这两种分别是指使用mp3和aac格式的音频
                                        //+ " -ar 22050"//设置音频采样率,对于音频的ar（采样率）可以指定为22050、24000、44100或48000，一般来将后两种比较常见
                                        //+ " -qmin 2"//
                                        //+ " -qmax 16"//
                                        //+ " -b 320k"//设置比特率,缺省200kb/s
                                        //    //+ " -qscale 6"//使用动态码率来设置
                                        //+ " -r 29.97" //设置帧频,缺省25
                                        //+ " -s " + strBigImage //视频尺寸
                                        //+ " -ss " + strCutTime[0]
                                        //+ " -t " + strCutTime[1]
                                        //+ " " + strCutVideoPath, false);
                                        //txtStatus.Text += "预览文件\"" + strVideoPath + "\"转换完毕！\r\n";
                                        #endregion
                                        string strBigImagePath = strTempSavePath.Replace(".flv", "_Big.jpg");
                                        string strSmallImagePath = strTempSavePath.Replace(".flv", "_Small.jpg");

                                        if (File.Exists(strBigImagePath))
                                        {
                                            File.Delete(strBigImagePath);
                                        }
                                        if (File.Exists(strSmallImagePath))
                                        {
                                            File.Delete(strSmallImagePath);
                                        }

                                        CreateProcessForFFMpeg(strFfmpegPath, " -i \"" + strOldPath + "\" -y -f image2 -ss 10 -t 0.005 -s \"" + strBigImage + "\" \"" + strBigImagePath + "\"", false);
                                        txtStatus.Text += "文件\"" + strOldPath + "\"视频截图（大）生成完毕！\r\n";
                                        CreateProcessForFFMpeg(strFfmpegPath, " -i \"" + strOldPath + "\" -y -f image2 -ss 10 -t 0.005 -s \"" + strSmallImage + "\" \"" + strSmallImagePath + "\"", false);
                                        txtStatus.Text += "文件\"" + strOldPath + "\"视频截图（小）生成完毕！\r\n";


                                        txtStatus.Text += "文件\"" + strOldPath + "\"视频长度获取成功！\r\n";
                                        string strTemp = System.Configuration.ConfigurationSettings.AppSettings["SavePath"].ToString();
                                        strTempSavePath = strTempSavePath.Replace(strTemp, "").Replace("\\", "/");
                                        strBigImagePath = strBigImagePath.Replace(strTemp, "").Replace("\\", "/");
                                        strSmallImagePath = strSmallImagePath.Replace(strTemp, "").Replace("\\", "/");
                                        txtStatus.Text += "文件转换成功！\r\n";
                                        //ws.ConvertSuccess(iFileID, iTimeLength, strTempSavePath, strBigImagePath, strSmallImagePath);
                                    }
                                    else
                                    {
                                        txtStatus.Text += "文件\"" + strOldPath + "\"转换失败！\r\n";
                                        //ws.ConvertFail(iFileID);
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                    #endregion
                    #region 转换文档
                    else
                    {
                        //开始转换 转换视频用的是pffmpeg 截视频用ffmpeg；

                        string strFileName = strVideoPath.Substring(strVideoPath.LastIndexOf('/') + 1);
                        int iFileLen = GetPageCount(strOldPath);//页数
                        string strBigimage = strVideoPath.Replace(strFileType, "_big.jpg");
                        string strSmalimage = strVideoPath.Replace(strFileType, "_small.jpg");
                        #region 文档格式
                        if (strFileType.ToLower() != ".swf")
                        {
                            strFileName = strFileName.Replace(strFileType, ".swf");


                            int iCount = iFileLen % 5 == 0 ? iFileLen / 5 : iFileLen / 5 + 1;
                            for (int i = 0; i < iCount; i++)
                            {
                                string strTempName = strFileName;//大图片保存的路径
                                string strTempBig = strBigimage;//小图路径
                                string strTempSmal = strSmalimage;

                                if (i > 0)
                                {
                                    strTempName = strFileName.Substring(0, strFileName.LastIndexOf('.')) + "_" + i + ".swf";
                                    strTempBig = strVideoPath.Replace(strFileType, i + "_big.jpg");
                                    strTempSmal = strVideoPath.Replace(strFileType, i + "_small.jpg");
                                }
                                if (ConverDoc((i * 5) + 1, (i + 1) * 5, strOldPath, strTempSavePath + strTmepPath, strTempName))
                                {
                                    SwfToImage(strTempSavePath + strTmepPath + "/" + strTempName, strTempBig, strTempSmal);
                                }
                            }
                            //string strTemp = System.Configuration.ConfigurationSettings.AppSettings["SavePath"].ToString();

                        }
                        #endregion

                        #region swf格式
                        else
                        {
                            SwfToImage(strOldPath, strBigimage, strSmalimage);
                            if (!File.Exists(strTempSavePath + strVideoPath))
                            {
                                File.Copy(strOldPath, strTempSavePath + strVideoPath);
                            }
                        }
                        #endregion
                        //ws.ConvertSuccess(iFileID, 0, strTmepPath + "/" + strFileName, strBigimage, strSmalimage);
                        txtStatus.Text += "文件转换成功！\r\n";
                        //ws.ConvertSuccess(iFileID, iFileLen, strTmepPath + strFileName, "",strImagePath);

                    }
                    #endregion
                }
                else
                {
                    txtStatus.Text += "文件\"" + strOldPath + "\"不存在！\r\n";
                    //ws.ConvertFail(iFileID);
                }

            }
            catch (Exception ex)
            {
                txtStatus.Text += ex.Message + "\r\n";
                //ws.ConvertFail(iFileID);
            }
            finally
            {
                txtStatus.ScrollToCaret();
            }
        }

        /// <summary>
        /// 获取视频类别号
        /// </summary>
        /// <param name="strFileType"></param>
        /// <returns>1-文档，2视频，3-MP3</returns>
        private int getExtension(string strFileType)
        {
            int iExt = 0;

            string strDocFormat = System.Configuration.ConfigurationSettings.AppSettings["DocFormat"].ToString();//文档格式
            string strMp3Format = System.Configuration.ConfigurationSettings.AppSettings["Mp3"].ToString();//mp3
            string strModelFormat = ConfigurationSettings.AppSettings["Model"].ToString();
            return iExt;
        }
        /// <summary>
        /// 转换文件
        /// </summary>
        /// <param name="iStartPage">开始页</param>
        /// <param name="iEndPage">结束页</param>
        /// <param name="strOldPath">文件路径</param>
        /// <param name="strTempSavePath">保存路径 最后无 /</param>
        /// <param name="strFileName">文件名</param>
        private bool ConverDoc(int iStartPage, int iEndPage, string strOldPath, string strTempSavePath, string strFileName)
        {
            bool flag = false;
            try
            {
                string command = Application.StartupPath + (@"\pdf2swf.exe");
                StringBuilder sb = new StringBuilder();
                if (!Directory.Exists(strTempSavePath))
                {
                    Directory.CreateDirectory(strTempSavePath);
                }
                strTempSavePath = strTempSavePath + @"/" + strFileName;
                #region pdf to swf
                sb.Append(" -o \"" + strTempSavePath + "\"");//output   

                sb.Append(" -s flashversion=9");//flash version   

                sb.Append(" -s disablelinks");//禁止PDF里面的链接   

                sb.Append(" -p " + iStartPage + "-" + iEndPage);//page range   

                sb.Append(" -j 100");//Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)   

                sb.Append(" \"" + strOldPath + "\"");//input 
                Process proc = new Process();

                proc.StartInfo.FileName = command;
                proc.StartInfo.Arguments = sb.ToString();
                proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.Start();
                proc.WaitForExit();
                proc.Close();
                #endregion

                //#region swf to image
                //SwfToImage(strTempSavePath);
                //#endregion
                flag = true;
            }
            catch (ArgumentException ex)
            {
                txtStatus.Text += "文件转换失败！\r\n";
                flag = false;
            }
            return flag;
        }
        /// <summary>
        /// swf截图
        /// </summary>
        /// <param name="strTempSavePath">源文件路径</param>
        /// <param name="strBigImagePath">截图（大）相对路径</param>
        /// <param name="strSmallImagePath">截图（小）相对路径</param>
        private static void SwfToImage(string strTempSavePath, string strBigImagePath, string strSmallImagePath)
        {
            /*   缺少 SWFToImage 引用，注释 20120722
            //string strSmallImagePath = strTempSavePath.Replace(".swf", "_small.jpg");
            //string strBigImagePath = strTempSavePath.Replace(".swf","_big.jpg");
            string strSavePth = System.Configuration.ConfigurationSettings.AppSettings["SavePath"].ToString();
            string[] strImageSize = System.Configuration.ConfigurationSettings.AppSettings["SmallImage"].ToString().Split('x');
            string[] strBigSize = System.Configuration.ConfigurationSettings.AppSettings["BigImage"].ToString().Split('x');
            SWFToImage.SWFToImageObjectClass swf = new SWFToImageObjectClass();
            swf.InputSWFFileName = strTempSavePath;
            swf.ImageOutputType = TImageOutputType.iotJPG;
            swf.ImageWidth = int.Parse(strImageSize[0]);
            swf.ImageHeight = int.Parse(strImageSize[1]);
            swf.Execute();
            swf.SaveToFile(strSavePth+"/"+ strSmallImagePath);
            
            swf.InputSWFFileName = strTempSavePath;
            swf.ImageOutputType = TImageOutputType.iotJPG;
            swf.ImageWidth = int.Parse(strBigSize[0]);
            swf.ImageHeight = int.Parse(strBigSize[1]);
            swf.Execute();
            swf.SaveToFile(strSavePth+"/"+ strBigImagePath);
            */
        }
        private int GetSecondsByString(string str)
        {
            if (string.IsNullOrEmpty(str))
                return 0;

            int intCountSeconds = 0;
            //小时
            int intHours = 0;
            Int32.TryParse(str.Substring(0, str.IndexOf(":")), out intHours);
            if (intHours > 0)
                intCountSeconds += intHours * 3600;
            //分钟
            int intMinutes = 0;
            Int32.TryParse(str.Substring(str.IndexOf(":") + 1, 2), out intMinutes);
            if (intMinutes > 0)
                intCountSeconds += intMinutes * 60;
            //秒钟
            int intSeconds = 0;
            Int32.TryParse(str.Substring(str.LastIndexOf(":") + 1, 2), out intSeconds);
            if (intSeconds > 0)
                intCountSeconds += intSeconds;

            return intCountSeconds;
        }

        /// <summary>
        /// 调用ffmpeg.exe执行相应操作
        /// </summary>
        /// <param name="stringPath">ffmpeg.exe所在路径（如:E:\ttt\ffmpeg.exe）</param>
        /// <param name="stringArguments">给ffmpeg.exe传递的参数</param>
        /// <returns></returns>
        public bool CreateProcessForFFMpeg(string stringPath, string stringArguments, bool boolShowDosWindow)
        {
            if (!System.IO.File.Exists(stringPath))
                return false;

            ProcessStartInfo info3 = new ProcessStartInfo(stringPath);
            if (boolShowDosWindow)
                info3.WindowStyle = ProcessWindowStyle.Normal;
            else
                info3.WindowStyle = ProcessWindowStyle.Hidden;

            info3.Arguments = stringArguments;

            Process proc = new Process();
            proc = Process.Start(info3);

            proc.WaitForExit();

            proc.Close();

            return true;

        }



        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (nonParameterThread != null && nonParameterThread.ThreadState != System.Threading.ThreadState.Unstarted && nonParameterThread.ThreadState != System.Threading.ThreadState.Stopped)
            {
                nonParameterThread.Abort();
                nonParameterThread.Join();
            }
            nonParameterThread = null;
        }

        private void notify_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
            this.notify.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            f1.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string oldPath = @"E:\dat\hunsudaguan2.DAT";
            string newPath = @"E:\dat\hunsudaguan2.flv";


        }


        //private void Main_SizeChanged(object sender, EventArgs e)
        //{
        //    if (this.WindowState == FormWindowState.Minimized)
        //    {
        //        this.Hide();
        //        this.notify.Visible = true;
        //    }
        //}


    }
}
